<template>
  <div class="app-container">
    <div class="filter-container">
      <el-select v-model="searchForm.item_id" class="filter-item" style="width: 130px;" clearable :loading="listLoading" placeholder="选择道具">
        <el-option v-for="item in cfg_items" :key="item.item_id" :label="item.item_name" :value="item.item_id"></el-option>
      </el-select>
      <statisSearchBar :show-channel="false" :start-date="searchForm.startDate" :end-date="searchForm.endDate" @transferFilter="handleFilter" />
    </div>
    <el-table v-loading="listLoading" :data="list" class="mt-10" border height="710">
      <el-table-column label="序号" prop="index" width="110px" align="center"></el-table-column>
      <el-table-column label="来源" prop="source" width="170px" align="center"></el-table-column>
      <el-table-column label="道具消耗数量" prop="amount" width="170px" align="center"></el-table-column>
      <el-table-column label="消耗占比" prop="amount_ratio" width="98px" align="center"></el-table-column>
      <el-table-column label="消耗人数" prop="num" width="98px" align="center"></el-table-column>
      <el-table-column label="人均消耗" prop="amount_per" width="98px" align="center"></el-table-column>
    </el-table>
  </div>
</template>

<script>
import StatisSearchBar from '@/components/StatisSearchBar'
import { getItemStaticRank, getCfgStItemList } from '@/api/statis'
const defaultSearchForm = {
  item_id: 17
}
export default {
  name: 'ConsumeRank',
  components: { StatisSearchBar },
  data() {
    return {
      list: [],
      listLoading: false,
      cfg_items: [],
      searchForm: {
        startDate: new Date(Date.now() - 86400000 * 10),
        endDate: new Date(),
        ...defaultSearchForm
      }
    }
  },
  created() {
    this.getCfgStItemList()
  },
  methods: {
    handleFilter(query) {
      this.searchForm = { ...defaultSearchForm, ...this.searchForm, ...query }
      this.getList()
    },
    async getList() {
      this.listLoading = true
      const res = await getItemStaticRank(Object.assign(this.searchForm, { log_type: 8 }))
      this.listLoading = false
      this.list = res.data
    },
    async getCfgStItemList() {
      const res = await getCfgStItemList()
      this.cfg_items = res.data.list
      this.getList()
    }
  }
}
</script>
